<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/5/8
  Time: 12:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>租户管理</title>
</head>
<body>
<div id="tenant_tb">
    <input class="easyui-textbox" name="username" data-options="label:'账号', labelAlign:'right', labelWidth:30">
    <input class="easyui-textbox" name="name" data-options="label:'名称', labelAlign:'right', labelWidth:40">
    <input class="easyui-textbox" name="type" data-options="label:'类型', labelAlign:'right', labelWidth:40">
    <input class="easyui-textbox" name="address" data-options="label:'地址', labelAlign:'right', labelWidth:40">
    <input class="easyui-textbox" name="representative" data-options="label:'法人代表', labelAlign:'right', labelWidth:70">
    <a class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="queryTenant()">查询</a>
    <br>
    <a class="easyui-linkbutton" onclick="addTenant()" data-options="iconCls:'icon-add',plain:true">新增</a>
    <a class="easyui-linkbutton" onclick="deleteTenant()" data-options="iconCls:'icon-remove',plain:true">删除</a>
    <a class="easyui-linkbutton" onclick="editTenant()" data-options="iconCls:'icon-edit',plain:true">修改</a>
</div>
<table id="tenant_dg"></table>
<script>
    $(function () {
        $('#tenant_dg').datagrid({
            method:'post',
            fitColumns:true,
            nowrap:true,
            fit:true,
            ctrlSelect:true,
            scrollbarSize:0,
            url:'../tenant/findAllTenants',
            columns:[[
                {field:'id',title:'id',width:11,hidden:true},
                {field:'username',title:'账号',width:11},
                {field:'password',title:'密码',width:11},
                {field:'name',title:'名称',width:11},
                {field:'type',title:'类型',width:11},
                {field:'address',title:'地址',width:11},
                {field:'representative',title:'法人代表',width:11},
                {field:'number',title:'电话',width:11},
                {field:'email',title:'email',width:12}
            ]],
            pagination:true,
            toolbar:'#tenant_tb'
        });

        $('#tenant_dg').datagrid('getPager').pagination({
            beforePageText:'第',
            afterPageText:'页，共{pages}页',
            displayMsg:'当前显示第{from}到{to}条，共{total}条'
        });
    });

    function addTenant() {
        if ($('#tt').tabs('exists', '添加租户')) {
            $('#tt').tabs('select', '添加租户');
        } else {
            $('#tt').tabs('add', {
                title:'添加租户',
                closable:true,
                href:'../tenant/getAddTenantView'
            });
        }
    }

    function deleteTenant() {
        var row = $('#tenant_dg').datagrid('getSelected');
        if (row === null) {
            return;
        } else {
            $.messager.confirm({
                title: '确认',
                msg: '确定要删除吗？',
                ok:'确认',
                cancel:'取消',
                fn: function(r){
                    if (r){
                        var index = $('#tenant_dg').datagrid('getRowIndex', row);
                        $.ajax({
                            url:'../tenant/deleteTenant',
                            type:'post',
                            data:'id=' + row.id,
                            dataType:'json',
                            success:function (data) {
                                //var d = eval('(' + data + ')');
                                if (data.result === 'success') {
                                    $('#tenant_dg').datagrid('deleteRow', index);
                                }
                                $.messager.alert('提示', data.message, 'info');
                            },
                            error:function (data) {
                                $.messager.alert('提示', data, 'info');
                            }
                        });
                    }
                }
            });
        }
    }

    function editTenant() {
        var row = $('#tenant_dg').datagrid('getSelected');
        if (row == null) {
            return;
        } else {
            $('#tt').tabs('close', '修改租户');
            $('#tt').tabs('add', {
                title:'修改租户',
                closable:true,
                href:'../tenant/getEditTenantView',
                method:'post',
                queryParams:{
                    id:row.id,
                    username:row.username,
                    password:row.password,
                    name:row.name,
                    type:row.type,
                    address:row.address,
                    representative:row.representative,
                    number:row.number,
                    email:row.email
                }
            });
        }
    }

    function queryTenant() {
        var data = {
            username:$("input[name='username']").val(),
            name:$("input[name='name']").val(),
            type:$("input[name='type']").val(),
            address:$("input[name='address']").val(),
            representative:$("input[name='representative']").val()
        };
        $('#tenant_dg').datagrid('load', data);
    }
</script>
</body>
</html>
